import { Injectable } from "@angular/core";
import { HttpClient, HttpResponse } from "@angular/common/http";

import { Observable, of } from "rxjs";

import { SrcType } from "../../shared/domain";
// import { SCRTYPES } from './mock-srcTypes';
import { MessageService } from "../../message.service";
import { DtoInfo, MethodInfo, AttributeInfo } from "../../shared";
import { DTOINFOS, METHODINFOS, ATTRIBUTEINFOS } from "../store";

@Injectable({
  providedIn: "root",
})
export class CreateService {
  constructor(
    private http: HttpClient,
    private messageService: MessageService
  ) {}

  getSrcTypes(inputScreenId: string): Observable<SrcType[]> {
    // TODO: send the message _after_ fetching the heroes
    this.messageService.add("SrcTypeService: fetched SrcTypes");

    const data = {
      keyword: inputScreenId,
    };

    return this.http.get<SrcType[]>("getSrcTypes", { params: data });
  }

  createSource(
    inputScreenId: string,
    classId: string,
    classPakage: string,
    classType: string
  ): Observable<HttpResponse<Blob>> {
    // TODO: send the message _after_ fetching the heroes
    this.messageService.add("SrcTypeService: fetched CreateSource");

    const data = {
      screenId: inputScreenId,
      classId: classId,
      classPakage: classPakage,
      classType: classType,
    };

    return this.http.get("createSource", {
      params: data,
      responseType: "blob",
      observe: "response",
    });
  }

  createJunit(
    inputScreenId: string,
    classId: string,
    classPakage: string,
    classType: string
  ): Observable<HttpResponse<Blob>> {
    // TODO: send the message _after_ fetching the heroes
    this.messageService.add("SrcTypeService: fetched createSourceJunit");

    const data = {
      screenId: inputScreenId,
      classId: classId,
      classPakage: classPakage,
      classType: classType,
    };

    return this.http.get("createSourceJunit", {
      params: data,
      responseType: "blob",
      observe: "response",
    });
  }

  getDtoInfos(): Observable<DtoInfo[]> {
    return of(DTOINFOS);
  }

  getMethodInfos(): Observable<MethodInfo[]> {
    return of(METHODINFOS);
  }

  getAttributeInfos(): Observable<AttributeInfo[]> {
    return of(ATTRIBUTEINFOS);
  }
}
